package com.dc.modules.sys.menu;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dc.commons.query.DcQuery;
import com.dc.commons.service.BaseService;
import com.dc.modules.sys.menu.domain.DcSysMenu;
import com.dc.modules.sys.menu.repository.DcSysMenuRepository;

/*******************************************************************************<P>
 * 文件名: DcSysMenuService.java <br>
 * 版本: 1.0<br>
 * 描述:<br>
 * 版权所有: <br>
 * <P>
 * 创建者: 王建栋 <br>
 * 创建日期: 2016年6月22日 下午7:08:16<br>
 * 修改者: <br>
 * 修改日期: <br>
 * 修改说明: <br>
 ******************************************************************************/
@Service
public class DcSysMenuService extends BaseService<DcSysMenu>{
	
	@Autowired
	private DcSysMenuRepository dcSysMenuRepository;
	
	/**
	 * 菜单管理
	 * @param dcSysMenu
	 * @return
	 */
	@Transactional(readOnly=true)
	public DcSysMenu sysMenuManager(DcSysMenu dcSysMenu){
		return dcSysMenu;
	}
	
	/**
	 * 菜单查询
	 * @return
	 */
	@Transactional(readOnly=true)
	public List<DcSysMenu> queryList(DcQuery dcQuery){
		List<DcSysMenu>  list= dcSysMenuRepository.findAll(dcQuery.buildSpecification(DcSysMenu.class),dcQuery.getPageable().getSort());
		return list;
	}
	
	/**
	 *  到新增菜单页面
	 * @param dcSysMenu
	 * @return
	 */
	@Transactional(readOnly=true)
	public DcSysMenu sysMenuAdd(DcSysMenu dcSysMenu){
		return dcSysMenu;
	}
	
	/**
	 * 新增菜单
	 * @param dcSysMenu
	 * @return dcSysMenu
	 */
	public DcSysMenu addSysMenu(DcSysMenu dcSysMenu){
		dcSysMenu=dcSysMenuRepository.saveTree(dcSysMenu);
		return dcSysMenu;
	}
	
	/**
	 * 到修改菜单页面
	 * @param dcSysMenu
	 * @return
	 */
	@Transactional(readOnly=true)
	public DcSysMenu sysMenuEdit(DcSysMenu dcSysMenu){
		return dcSysMenu;
	}
	
	/**
	 *  修改菜单
	 * @param dcSysMenu
	 * @return
	 */
	public DcSysMenu editSysMenu(DcSysMenu dcSysMenu){
		dcSysMenu=dcSysMenuRepository.updateTree(dcSysMenu);
		return dcSysMenu;
	}
	
	/**
	 * 根据主键查询菜单
	 * @param id
	 * @return
	 */
	@Transactional(readOnly=true)
	public DcSysMenu findSysMenu(String id){
		DcSysMenu dcSysMenu=dcSysMenuRepository.findOne(id);
		return dcSysMenu;
	}
	
	/**
	 * 删除菜单
	 * @param dcSysMenu
	 * @return
	 */
	public DcSysMenu deleteSysMenu(DcSysMenu dcSysMenu){
		dcSysMenuRepository.deleteTree(dcSysMenu);
		return dcSysMenu;
	}
	
	
	/**
	 * 拖动菜单
	 * @param dcQuery
	 */
	public void dragSysMenu(DcQuery dcQuery){
		dcSysMenuRepository.drag(dcQuery.getFrom(),dcQuery.getTo(),dcQuery.getMoveType());
	}
	
}
